def resource_to_create
  instance = JSON.parse(resource_to_request)
  instance['name'] =
    "projects/#{resource[:project]}/instances/#{resource[:name]}"
  instance['config'] =
    "projects/#{resource[:project]}/instanceConfigs/#{resource[:config]}"
  {
    'instanceId' => resource[:name],
    'instance' => instance
  }.to_json
end

def resource_to_update
  instance = JSON.parse(resource_to_request)
  instance['name'] =
    "projects/#{resource[:project]}/instances/#{resource[:name]}"
  instance['config'] =
    "projects/#{resource[:project]}/instanceConfigs/#{resource[:config]}"
  {
    'instance' => instance,
<% fields = object.properties.select { |p| !p.output }.map(&:name) -%>
    'fieldMask' => %w[<%= fields.join(' ') -%>].join(',')
  }.to_json
end

def decode_response(response)
  self.class.decode_response(response)
end

def self.decode_response(response)
  response = JSON.parse(response.body)
  return response if response.empty?
  # Don't alter if it's a async operation
  return response if response['name'].include? '/operations/'

  response['name'] = response['name'].split('/').last
  response['config'] = response['config'].split('/').last
  response
end
